package com.qf.common.oss.controller;



import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import com.qf.common.oss.service.FileUploadService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.ByteArrayInputStream;
import java.io.IOException;

@RestController
@RequestMapping("/upload")
// @Api(tags = "dfaad")
public class FileUploadController {
    @Resource
    private FileUploadService fileUploadService;

    @PostMapping("/images")
    @ResponseBody
    public String uploadImage(MultipartFile file) {

        // PutObjectRequest putObjectRequest = new PutObjectRequest(cloudVo.getBucketName(), fileUrl, new ByteArrayInputStream(multipartFile.getBytes()), objectMetadata);
        String upload;
        try {
            upload = fileUploadService.upload(file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return upload;
    }
}
